package com.lrd.snapshotorder.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lrd.snapshotorder.entity.RecipientAddress;
import com.lrd.snapshotorder.protocol.dto.address.RecipientAddressQueryDto;

import java.util.List;
import java.util.Objects;

public interface RecipientAddressMapper extends BaseMapper<RecipientAddress> {

    default Page<RecipientAddress> queryRecipientAddressList(RecipientAddressQueryDto dto) {
        return this.selectPage(
                new Page<>(dto.getPageIndex(), dto.getPageSize()),
                Wrappers.lambdaQuery(RecipientAddress.class)
                        .like(StringUtils.isNotBlank(dto.getRecipient()), RecipientAddress::getRecipient, dto.getRecipient())
                        .like(StringUtils.isNotBlank(dto.getRecipientAddress()), RecipientAddress::getRecipientAddress, dto.getRecipientAddress())
                        .eq(Objects.nonNull(dto.getStatus()), RecipientAddress::getStatus, dto.getStatus()));
    }

    default List<RecipientAddress> getAllList() {
        return this.selectList(
                Wrappers.lambdaQuery(RecipientAddress.class)
                        .eq(RecipientAddress::getStatus, 1)
        );
    }
}